﻿//////////////////////////////////////////////////////////////////
//
// Messages\LoadTile.cs
//
// Copyright (c) 2012 Dan Pike.
//
// Permission is hereby granted, free of charge, to any person
// obtaining a copy of this software and associated documentation files
// (the "Software"), to deal in the Software without restriction,
// including without limitation the rights to use, copy, modify, merge,
// publish, distribute, sublicense, and/or sell copies of the Software,
// and to permit persons to whom the Software is furnished to do so,
// subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included
// in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
// CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
// TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
// SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using Interfaces;
using ProtoBuf;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Messages
{
   public class LoadTile : Message<LoadTile>, ILoadTile
   {
      private string planetName_;
      private ILocation location_;

      ////////////////////////////////////////////////////////////////////////
      /// <summary>
      /// 
      /// </summary>
      public LoadTile()
         : base(ProtoBufTags.ILoadTile)
      {
      }

      ////////////////////////////////////////////////////////////////////////
      /// <summary>
      /// Implementation of ILoadTile
      /// </summary>
      [ProtoMember((int)ProtoBufTags.LoadTilePlanetName)]
      public string PlanetName
      {
         get { return planetName_; }
         set { planetName_ = value; }
      }

      ////////////////////////////////////////////////////////////////////////
      /// <summary>
      /// Implementation of ILoadTile
      /// 
      /// Note that we serialize this via a __hack property to avoid adding
      /// the ProtoInclude() nastiness to ILocation
      /// </summary>
      public ILocation Location
      {
         get { return location_; }
         set { location_ = value; }
      }

      ////////////////////////////////////////////////////////////////////////
      /// <summary>
      /// ProtoBuf.Net cannot handle interfaces in the way that we want. It would
      /// be necessary to adulterate the Interfaces assembly with protobuf-net and
      /// connect to all of the concrete classes and that would kill the plugin-
      /// architecture
      /// </summary>
      [ProtoMember((int)ProtoBufTags.LoadTileLocation)]
      public float[] __hack_for_protobuf
      {
         get
         {
            if (null != location_)
            {
               return new float[3] { location_.Longitude, location_.Latitude,
                  location_.Altitude };
            }
            return null;
         }
         set
         {
            location_ = Program.Loader.Create<ILocation>();
            location_.Longitude = value[0];
            location_.Latitude = value[1];
            location_.Altitude = value[2];
         }
      }
   }
}
